<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #content{
            padding: 15px 15px 0 20px;
        }
        table{
            width: 100%;
            /*border: 1px solid;*/
            margin: auto;
            border-collapse: collapse;
        }
        th{
            text-align: center;
            padding: 3px 0px;
        }
        table tr td{
            margin: auto;
            padding: 6px 15px;
            /*border: 1px solid;*/
            text-align: center;
        }
    </style>
</head>
<body>
<div id="content">
    <table border="">
        <thead>
        <tr>
            <th>id</th>
            <th>名称</th>
            <th>分类内容</th>
            <th>增加时间</th>
            <th>修改时间</th>
        </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
</div>

<script>
    let xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readyState == 4 && xmlhttp.status==200) {
            let json = JSON.parse(xmlhttp.responseText);

            let string = document.getElementById('content').innerHTML;
            let value = json.date;

            let tbody = document.querySelector('tbody');
            for (let i = 0; i < value.length; i++) {
                let tr = document.createElement('tr');
                tbody.appendChild(tr);
                for (let k in value[i]) {
                    let td = document.createElement('td');
                    if(k == 'update_time' || k == 'add_time'){
                        let date = new Date(value[i][k]*1000);
                        let year = date.getFullYear();
                        let month = date.getMonth()+1;
                        let time =date.getDate();
                        let hours = date.getHours();
                        let minute = date.getMinutes();
                        let second  = date.getSeconds();
                        td.innerHTML = year +'-'+month.toString().padStart(2,'')+'-'+
                                time.toString().padStart(2,'')+' '+hours.toString().padStart(2,'0')+':'+
                                minute.toString().padStart(2,'0') +':'+second.toString().padStart(2,'0');

                    }else{
                        td.innerHTML = value[i][k];
                    }
                    // td.innerHTML = value[i][k];
                    tr.appendChild(td);
                }
            }
        }

    }
    xmlhttp.open('POST','index.php?s=index/api/api_list');
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send();
</script>
</body>
</html>